package com.ruoyi.service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.entity.BizParkingLot;
import com.ruoyi.mapper.BizParkingLotMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.BizParkingLotFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 停车场信息表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-20
 */
@Service
@DataSource(value = DataSourceType.SLAVE)  //切换数据源
public class BizParkingLotService extends ServiceImpl<BizParkingLotMapper, BizParkingLot> {

	public ResponseData create(BizParkingLotFrom bizParkingLot) {
		BizParkingLot entity = transformationFrom(bizParkingLot);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(BizParkingLotFrom bizParkingLot) {
		if(findById(bizParkingLot.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		BizParkingLot entity = transformationFrom(bizParkingLot);
		entity.setId(bizParkingLot.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public BizParkingLot transformationFrom(BizParkingLotFrom bizParkingLot) {
		BizParkingLot entity = new BizParkingLot();
		entity.setPlCode(bizParkingLot.getPlCode());
		entity.setPlName(bizParkingLot.getPlName());
		entity.setPlState(bizParkingLot.getPlState());
		entity.setPlCount(bizParkingLot.getPlCount());
		entity.setRemark(bizParkingLot.getRemark());
		entity.setLatitude(bizParkingLot.getLatitude());
		entity.setLongitude(bizParkingLot.getLongitude());
		entity.setPlAddress(bizParkingLot.getPlAddress());
		entity.setPhoneNumber(bizParkingLot.getPhoneNumber());
		entity.setProvince(bizParkingLot.getProvince());
		entity.setProvinceName(bizParkingLot.getProvinceName());
		entity.setCity(bizParkingLot.getCity());
		entity.setCityName(bizParkingLot.getCityName());
		entity.setArea(bizParkingLot.getArea());
		entity.setAreaName(bizParkingLot.getAreaName());
		entity.setCompanyId(bizParkingLot.getCompanyId());
		entity.setDepartmentId(bizParkingLot.getDepartmentId());
		entity.setIsDeleted(bizParkingLot.getIsDeleted());
		entity.setPropertyWithdrawChannel(bizParkingLot.getPropertyWithdrawChannel());
		entity.setCreator(bizParkingLot.getCreator());
		entity.setCreateTime(bizParkingLot.getCreateTime());
		entity.setModifier(bizParkingLot.getModifier());
		entity.setPayChannel(bizParkingLot.getPayChannel());
		entity.setModifyTime(bizParkingLot.getModifyTime());
		entity.setLeaveTime(bizParkingLot.getLeaveTime());
		entity.setEquipment(bizParkingLot.getEquipment());
		entity.setConnectPassword(bizParkingLot.getConnectPassword());
		entity.setIsShow(bizParkingLot.getIsShow());
		entity.setIsAppShow(bizParkingLot.getIsAppShow());
		return entity;
	}

	public BizParkingLotFrom transformationBean(BizParkingLot bizParkingLot) {
		BizParkingLotFrom from = new BizParkingLotFrom();
		from.setPlCode(bizParkingLot.getPlCode());
		from.setPlName(bizParkingLot.getPlName());
		from.setPlState(bizParkingLot.getPlState());
		from.setPlCount(bizParkingLot.getPlCount());
		from.setRemark(bizParkingLot.getRemark());
		from.setLatitude(bizParkingLot.getLatitude());
		from.setLongitude(bizParkingLot.getLongitude());
		from.setPlAddress(bizParkingLot.getPlAddress());
		from.setPhoneNumber(bizParkingLot.getPhoneNumber());
		from.setProvince(bizParkingLot.getProvince());
		from.setProvinceName(bizParkingLot.getProvinceName());
		from.setCity(bizParkingLot.getCity());
		from.setCityName(bizParkingLot.getCityName());
		from.setArea(bizParkingLot.getArea());
		from.setAreaName(bizParkingLot.getAreaName());
		from.setCompanyId(bizParkingLot.getCompanyId());
		from.setDepartmentId(bizParkingLot.getDepartmentId());
		from.setIsDeleted(bizParkingLot.getIsDeleted());
		from.setPropertyWithdrawChannel(bizParkingLot.getPropertyWithdrawChannel());
		from.setCreator(bizParkingLot.getCreator());
		from.setCreateTime(bizParkingLot.getCreateTime());
		from.setModifier(bizParkingLot.getModifier());
		from.setPayChannel(bizParkingLot.getPayChannel());
		from.setModifyTime(bizParkingLot.getModifyTime());
		from.setLeaveTime(bizParkingLot.getLeaveTime());
		from.setEquipment(bizParkingLot.getEquipment());
		from.setConnectPassword(bizParkingLot.getConnectPassword());
		from.setIsShow(bizParkingLot.getIsShow());
		from.setIsAppShow(bizParkingLot.getIsAppShow());

		return from;
	}

	
	public BizParkingLotFrom findById(String id) {
		BizParkingLot entity = this.getOne(new QueryWrapper<BizParkingLot>().lambda()
				.eq(BizParkingLot::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		BizParkingLot bizParkingLot = new BizParkingLot();
		bizParkingLot.setId(id);
		this.updateById(bizParkingLot);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, BizParkingLotFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<BizParkingLot>().lambda()
				.eq(StringUtils.isNotEmpty(ibean.getPlCode()), BizParkingLot::getPlCode, ibean.getPlCode())
				.eq(StringUtils.isNotEmpty(ibean.getPlName()), BizParkingLot::getPlName, ibean.getPlName())
				.eq(StringUtils.isNotEmpty(ibean.getPlState()), BizParkingLot::getPlState, ibean.getPlState())
				.eq(ibean.getPlCount() != null, BizParkingLot::getPlCount, ibean.getPlCount())
				.eq(StringUtils.isNotEmpty(ibean.getRemark()), BizParkingLot::getRemark, ibean.getRemark())
				.eq(StringUtils.isNotEmpty(ibean.getLatitude()), BizParkingLot::getLatitude, ibean.getLatitude())
				.eq(StringUtils.isNotEmpty(ibean.getLongitude()), BizParkingLot::getLongitude, ibean.getLongitude())
				.eq(StringUtils.isNotEmpty(ibean.getPlAddress()), BizParkingLot::getPlAddress, ibean.getPlAddress())
				.eq(StringUtils.isNotEmpty(ibean.getPhoneNumber()), BizParkingLot::getPhoneNumber, ibean.getPhoneNumber())
				.eq(ibean.getProvince() != null, BizParkingLot::getProvince, ibean.getProvince())
				.eq(StringUtils.isNotEmpty(ibean.getProvinceName()), BizParkingLot::getProvinceName, ibean.getProvinceName())
				.eq(ibean.getCity() != null, BizParkingLot::getCity, ibean.getCity())
				.eq(StringUtils.isNotEmpty(ibean.getCityName()), BizParkingLot::getCityName, ibean.getCityName())
				.eq(ibean.getArea() != null, BizParkingLot::getArea, ibean.getArea())
				.eq(StringUtils.isNotEmpty(ibean.getAreaName()), BizParkingLot::getAreaName, ibean.getAreaName())
				.eq(ibean.getCompanyId() != null, BizParkingLot::getCompanyId, ibean.getCompanyId())
				.eq(ibean.getDepartmentId() != null, BizParkingLot::getDepartmentId, ibean.getDepartmentId())
				.eq(StringUtils.isNotEmpty(ibean.getIsDeleted()), BizParkingLot::getIsDeleted, ibean.getIsDeleted())
				.eq(StringUtils.isNotEmpty(ibean.getPropertyWithdrawChannel()), BizParkingLot::getPropertyWithdrawChannel, ibean.getPropertyWithdrawChannel())
				.eq(ibean.getCreator() != null, BizParkingLot::getCreator, ibean.getCreator())
				.eq(ibean.getCreateTime() != null, BizParkingLot::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifier() != null, BizParkingLot::getModifier, ibean.getModifier())
				.eq(StringUtils.isNotEmpty(ibean.getPayChannel()), BizParkingLot::getPayChannel, ibean.getPayChannel())
				.eq(ibean.getModifyTime() != null, BizParkingLot::getModifyTime, ibean.getModifyTime())
				.eq(ibean.getLeaveTime() != null, BizParkingLot::getLeaveTime, ibean.getLeaveTime())
				.eq(StringUtils.isNotEmpty(ibean.getEquipment()), BizParkingLot::getEquipment, ibean.getEquipment())
				.eq(StringUtils.isNotEmpty(ibean.getConnectPassword()), BizParkingLot::getConnectPassword, ibean.getConnectPassword())
				.eq(StringUtils.isNotEmpty(ibean.getIsShow()), BizParkingLot::getIsShow, ibean.getIsShow())
				.eq(StringUtils.isNotEmpty(ibean.getIsAppShow()), BizParkingLot::getIsAppShow, ibean.getIsAppShow())
				);
	}
}
